<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends arfaController {

	public function __construct()
	{
		parent::__construct();
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
	}


	public function index()
	{
		$this->form_validation->set_rules("username","Username","required");
		$this->form_validation->set_rules("password","Password","required");
		$this->load->model("m_user_model");
		if($this->form_validation->run() == false){
			$this->load->view('login');
		} else {
			$user	= $this->input->post("username");
			$pwd	= $this->input->post("password");
			$data 	= $this->m_user_model->get_by(array("USERNAME"=>$user,"PASSWORD"=>md5($pwd)));

			if (! empty($data))
			{
				$this->session->set_userdata('idUser', $data[0]['ID_USER']);
				$this->session->set_userdata('username', $data[0]['USERNAME']);
				$this->session->set_userdata('statusLogin', TRUE);

				redirect('master_responden');
			}
			else
			{
				$this->session->set_flashdata('message', 'Username atau Password yang anda masukan salah');
				redirect('login');
			}

		}
	}
	public function logout(){
		$this->session->sess_destroy();
		$this->index();
  		redirect(base_url());
	}
}